package com.leetcode.algorithm.y22.todo;

import java.util.HashSet;
import java.util.Set;

/**
 * 947. 移除最多的同行或同列石头
 * 
 * https://leetcode.cn/problems/most-stones-removed-with-same-row-or-column/
 * 
 * @author jie.deng
 *
 */
class Question0947Solution01 {
	
	public int removeStones(int[][] stones) {
		Set<Integer> rowSet = new HashSet<>();
		Set<Integer> colSet = new HashSet<>();
		int cnt = 0;
		int len = stones.length;
		for (int i = 0; i < len; i++) {
			int[] arr = stones[i];
			boolean rowFlag = rowSet.add(arr[0]);
			boolean colFlag = colSet.add(arr[1]);
			if (rowFlag && colFlag) {
				cnt++;
			}
		}
		return len - cnt;
	}
    
}